package com.halfsword.creativecraft.recipe;

import net.minecraft.core.NonNullList;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.Container;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;

/**
 * 机器配方基类
 */
public abstract class BaseMachineRecipe implements Recipe<Container> {
    protected final ResourceLocation id;
    protected final String group;
    protected final NonNullList<Ingredient> inputs;
    protected final ItemStack output;
    protected final int processingTime;

    public BaseMachineRecipe(ResourceLocation id, String group,
                             NonNullList<Ingredient> inputs,
                             ItemStack output,
                             int processingTime) {
        this.id = id;
        this.group = group;
        this.inputs = inputs;
        this.output = output;
        this.processingTime = processingTime;
    }

    // ===== 共同实现 =====
    @Override
    public ResourceLocation getId() {
        return id;
    }

    @Override
    public String getGroup() {
        return group;
    }

    @Override
    public NonNullList<Ingredient> getIngredients() {
        return inputs;
    }

    public int getProcessingTime() {
        return processingTime;
    }

    @Override
    public boolean canCraftInDimensions(int width, int height) {
        return true;
    }

    @Override
    public ItemStack assemble(Container container, RegistryAccess registries) {
        return output.copy();
    }

    @Override
    public ItemStack getResultItem(RegistryAccess registries) {
        return output.copy();
    }

    // ===== 需要子类实现 =====
    @Override
    public abstract boolean matches(Container container, Level level);

    // 添加抽象方法声明
    @Override
    public abstract RecipeSerializer<?> getSerializer();

    @Override
    public abstract RecipeType<?> getType();
}